package com.ruoyi.web.controller.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.web.controller.demo.domain.SysWarehouse;
import com.ruoyi.web.controller.mapper.SysWarehouseUseMapper;
import com.ruoyi.web.controller.demo.domain.SysWarehouseUse;
import com.ruoyi.web.controller.service.ISysWarehouseUseService;
import com.ruoyi.common.core.text.Convert;

/**
 * sys_warehouse_useService业务层处理
 * 
 * @author ruoyi
 * @date 2023-01-02
 */
@Service
public class SysWarehouseUseServiceImpl implements ISysWarehouseUseService 
{
    @Autowired
    private SysWarehouseUseMapper sysWarehouseUseMapper;

    /**
     * 查询sys_warehouse_use
     * 
     * @param id sys_warehouse_use主键
     * @return sys_warehouse_use
     */
    @Override
    public SysWarehouseUse selectSysWarehouseUseById(Long id)
    {
        return sysWarehouseUseMapper.selectSysWarehouseUseById(id);
    }

    /**
     * 查询sys_warehouse_use列表
     * 
     * @param sysWarehouseUse sys_warehouse_use
     * @return sys_warehouse_use
     */
    @Override
    public List<SysWarehouseUse> selectSysWarehouseUseList(SysWarehouseUse sysWarehouseUse)
    {
        return sysWarehouseUseMapper.selectSysWarehouseUseList(sysWarehouseUse);
    }

    /**
     * 新增sys_warehouse_use
     * 
     * @param sysWarehouseUse sys_warehouse_use
     * @return 结果
     */
    @Transactional
    @Override
    public int insertSysWarehouseUse(SysWarehouseUse sysWarehouseUse)
    {
        int rows = sysWarehouseUseMapper.insertSysWarehouseUse(sysWarehouseUse);
        insertSysWarehouse(sysWarehouseUse);
        return rows;
    }

    /**
     * 修改sys_warehouse_use
     * 
     * @param sysWarehouseUse sys_warehouse_use
     * @return 结果
     */
    @Transactional
    @Override
    public int updateSysWarehouseUse(SysWarehouseUse sysWarehouseUse)
    {
//        sysWarehouseUseMapper.deleteSysWarehouseById(sysWarehouseUse.getId());
        insertSysWarehouse(sysWarehouseUse);
        return sysWarehouseUseMapper.updateSysWarehouseUse(sysWarehouseUse);
    }

    /**
     * 批量删除sys_warehouse_use
     * 
     * @param ids 需要删除的sys_warehouse_use主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysWarehouseUseByIds(String ids)
    {
//        sysWarehouseUseMapper.deleteSysWarehouseByIds(Convert.toStrArray(ids));
        return sysWarehouseUseMapper.deleteSysWarehouseUseByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除sys_warehouse_use信息
     * 
     * @param id sys_warehouse_use主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysWarehouseUseById(Long id)
    {
//        sysWarehouseUseMapper.deleteSysWarehouseById(id);
        return sysWarehouseUseMapper.deleteSysWarehouseUseById(id);
    }

    /**
     * 新增sys_warehouse信息
     * 
     * @param sysWarehouseUse sys_warehouse_use对象
     */
    public void insertSysWarehouse(SysWarehouseUse sysWarehouseUse)
    {
        List<SysWarehouse> sysWarehouseList = sysWarehouseUse.getSysWarehouseList();
        Long id = sysWarehouseUse.getId();
        if (StringUtils.isNotNull(sysWarehouseList))
        {
            List<SysWarehouse> list = new ArrayList<SysWarehouse>();
            for (SysWarehouse sysWarehouse : sysWarehouseList)
            {
                sysWarehouse.setId(id);
                list.add(sysWarehouse);
            }
            if (list.size() > 0)
            {
                sysWarehouseUseMapper.batchSysWarehouse(list);
            }
        }
    }
}
